<%#
 Copyright 2013-2020 the original author or authors from the JHipster project.

 This file is part of the JHipster project, see https://www.jhipster.tech/
 for more information.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-%>
<div>
    <h2>
        <span id="user-management-page-heading" jhiTranslate="userManagement.home.title" data-cy="userManagementPageHeading">Users</span>

        <div class="d-flex justify-content-end">
            <button class="btn btn-info mr-2" (click)="handleSyncList()" [disabled]="isLoading">
                <fa-icon icon="sync" [spin]="isLoading"></fa-icon> <span jhiTranslate="userManagement.home.refreshListLabel">Refreh List</span>
            </button>
            <button class="btn btn-primary jh-create-entity" [routerLink]="['./new']">
                <fa-icon icon="plus"></fa-icon> <span jhiTranslate="userManagement.home.createLabel">Create a new User</span>
            </button>
        </div>
    </h2>

    <<%= jhiPrefixDashed %>-alert-error></<%= jhiPrefixDashed %>-alert-error>

    <<%= jhiPrefixDashed %>-alert></<%= jhiPrefixDashed %>-alert>

    <div class="table-responsive" *ngIf="users">
        <table class="table table-striped" aria-describedby="user-management-page-heading">
            <thead>
                <tr<% if (databaseType !== 'cassandra') { %> jhiSort [(predicate)]="predicate" [(ascending)]="ascending" [callback]="transition.bind(this)"<% } %>>
                    <th scope="col" <% if (databaseType !== 'cassandra') { %> jhiSortBy="id"<% } %>><span jhiTranslate="global.field.id">ID</span><% if (databaseType !== 'cassandra') { %> <fa-icon icon="sort"></fa-icon><% } %></th>
                    <th scope="col" <% if (databaseType !== 'cassandra') { %> jhiSortBy="login"<% } %>><span jhiTranslate="userManagement.login">Login</span><% if (databaseType !== 'cassandra') { %> <fa-icon icon="sort"></fa-icon><% } %></th>
                    <th scope="col" <% if (databaseType !== 'cassandra') { %> jhiSortBy="email"<% } %>><span jhiTranslate="userManagement.email">Email</span><% if (databaseType !== 'cassandra') { %> <fa-icon icon="sort"></fa-icon><% } %></th>
                    <th scope="col"></th>
                    <%_ if (enableTranslation) { _%>
                    <th scope="col" <% if (databaseType !== 'cassandra') { %> jhiSortBy="langKey"<% } %>> <span jhiTranslate="userManagement.langKey">Lang Key</span><% if (databaseType !== 'cassandra') { %> <fa-icon icon="sort"></fa-icon><% } %></th>
                    <%_ } _%>
                    <th scope="col"><span jhiTranslate="userManagement.profiles">Profiles</span></th>
                    <%_ if (databaseType !== 'cassandra') { _%>
                    <th scope="col" jhiSortBy="createdDate"><span jhiTranslate="userManagement.createdDate">Created Date</span> <fa-icon icon="sort"></fa-icon></th>
                    <th scope="col" jhiSortBy="lastModifiedBy"><span jhiTranslate="userManagement.lastModifiedBy">Last Modified By</span> <fa-icon icon="sort"></fa-icon></th>
                    <th scope="col" jhiSortBy="lastModifiedDate"><span jhiTranslate="userManagement.lastModifiedDate">Last Modified Date</span> <fa-icon icon="sort"></fa-icon></th>
                    <%_ } _%>
                    <th scope="col"></th>
                </tr>
            </thead>
            <tbody *ngIf="users">
                <tr *ngFor="let user of users; trackBy: trackIdentity">
                    <td><a [routerLink]="['./', user.login, 'view']">{{ user.id }}</a></td>
                    <td>{{ user.login }}</td>
                    <td>{{ user.email }}</td>
                    <td>
                        <button class="btn btn-danger btn-sm" (click)="setActive(user, true)" *ngIf="!user.activated"
                                jhiTranslate="userManagement.deactivated">Deactivated</button>
                        <button class="btn btn-success btn-sm" (click)="setActive(user, false)" *ngIf="user.activated"
                                [disabled]="!currentAccount || currentAccount.login === user.login" jhiTranslate="userManagement.activated">Activated</button>
                    </td>
                    <%_ if (enableTranslation) { _%>
                    <td>{{ user.langKey }}</td>
                    <%_ } _%>
                    <td>
                        <div *ngFor="let authority of user.authorities">
                            <span class="badge badge-info">{{ authority }}</span>
                        </div>
                    </td>
                    <%_ if (databaseType !== 'cassandra') { _%>
                    <td>{{ user.createdDate | date:'dd/MM/yy HH:mm' }}</td>
                    <td>{{ user.lastModifiedBy }}</td>
                    <td>{{ user.lastModifiedDate | date:'dd/MM/yy HH:mm' }}</td>
                    <%_ } _%>
                    <td class="text-right">
                        <div class="btn-group">
                            <button type="submit"
                                    [routerLink]="['./', user.login, 'view']"
                                    class="btn btn-info btn-sm">
                                <fa-icon icon="eye"></fa-icon>
                                <span class="d-none d-md-inline" jhiTranslate="entity.action.view">View</span>
                            </button>

                            <button type="submit"
                                    [routerLink]="['./', user.login, 'edit']"
                                    queryParamsHandling="merge"
                                    class="btn btn-primary btn-sm">
                                <fa-icon icon="pencil-alt"></fa-icon>
                                <span class="d-none d-md-inline" jhiTranslate="entity.action.edit">Edit</span>
                            </button>

                            <button type="button" (click)="deleteUser(user)"
                                    class="btn btn-danger btn-sm" [disabled]="!currentAccount || currentAccount.login === user.login">
                                <fa-icon icon="times"></fa-icon>
                                <span class="d-none d-md-inline" jhiTranslate="entity.action.delete">Delete</span>
                            </button>
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    <%_ if (databaseType !== 'cassandra') { _%>

    <div *ngIf="users">
        <div class="row justify-content-center">
            <jhi-item-count [page]="page" [total]="totalItems" [itemsPerPage]="itemsPerPage"></jhi-item-count>
        </div>

        <div class="row justify-content-center">
            <ngb-pagination [collectionSize]="totalItems" [(page)]="page" [pageSize]="itemsPerPage" [maxSize]="5" [rotate]="true" [boundaryLinks]="true" (pageChange)="transition()"></ngb-pagination>
        </div>
    </div>
    <%_ } _%>
</div>
